package com.ccx.library.util;

import com.baomidou.mybatisplus.annotation.TableId;
import com.ccx.library.function.annotation.TimeAt;
import com.ccx.library.module.user.entity.User;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * 实体类获取id
 */
public class ModelVoIdUtil {

    public static String getId(Object Vo){
        Field[] fields = Vo.getClass().getDeclaredFields();
        for (Field field : fields) {
            if (field.isAnnotationPresent(TableId.class)){
                TableId tableId = field.getAnnotation(TableId.class);
                return tableId.value();
            }
        }
        return null;
    }

    public static String getTime(Object Vo){
        Field[] fields = Vo.getClass().getDeclaredFields();
        for (Field field : fields) {
            if(field.getAnnotation(TimeAt.class)!=null){
                return field.getAnnotation(TimeAt.class).value();
            }
        }
        return null;
    }
}
